﻿using Microsoft.AspNetCore.Mvc;

namespace RuoVea.Swms.Server.Service;
/// <summary>
/// 库存变动历史服务
/// </summary>
[ApiExplorerSettings(GroupName = "V1")]
public partial class InventoryHistoryService : IApplicationService
{
    /// <summary>
    /// 
    /// </summary>
    private readonly SugarRepository<WmsInventoryHistory> _thisRepository;
    private readonly ICurrentUser _currentUser;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="thisRepository"></param>
    /// <param name="currentUser"></param>
    public InventoryHistoryService(SugarRepository<WmsInventoryHistory> thisRepository, ICurrentUser currentUser)
    {
        _thisRepository = thisRepository;
        _currentUser = currentUser;
    }

    /// <summary>
    /// 查询所有/分页
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns> 
    public async Task<RestfulResult<PageResult<WmsInventoryHistory>>> GetPagesAsync(PageParam? data)
    {
        var restful = new RestfulResult<PageResult<WmsInventoryHistory>>() { Code = CodeStatus.OK };
        data ??= new PageParam { PageNo = 1, PageSize = 10 };
        var query = await _thisRepository.AsQueryable()
            .ToPageAsync(data.PageNo, data.PageSize);

        restful.Data = query;
        return restful;
    }

    /// <summary>
    /// 所有
    /// </summary>
    /// <returns></returns>
    public async Task<RestfulResult<PageResult<WmsInventoryHistory>>> GetlistAsync()
    {
        var restful = new RestfulResult<PageResult<WmsInventoryHistory>>() { Code = CodeStatus.OK };
        PageParam data = new PageParam { PageNo = 1, PageSize = 100 };
        var query = await _thisRepository.AsQueryable()
             //.Where(u => u.IsDisable == YesOrNot.N)
             //.Where(u => u.Creator == _currentUser.UserId)
             //.OrderByDescending(u => u.IsDefault)
             .Select(u => u)
            .ToPageAsync(data.PageNo, data.PageSize);
        restful.Data = query;
        return restful;
    }
     
}

